import Mock from 'mockjs';
/* 模拟网络连接超时 --- 1000ms请求失败即登录失败 */
Mock.setup({
    timeout: 1000,
});
Mock.mock('http://localhost:8080/login', 'post', req => {
    const { username, password } = JSON.parse(req.body);
    // 匹配用户名密码
    if (username === 'admin' && password === '123456') {
        return {
            code: 200,
            success: true,
            msg: '登录成功',
            nickname: '用户1',
            //token:令牌
            token: '546L5qyj5oiR5Zac5qyi5L2g',
            role: 'administration',
        };
    } else {
        return {
            code: 100,
            msg: '账号或密码错误',
            data: {},
        };
    }
});
/*入职日期接口*/
Mock.mock('http://localhost:8080/in', 'get', () => {
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        time: '2021-09-05 00:00:00',
    };
});
/*菜单接口*/
const menuList = [
    {
        name: '首页',
        icon: 'el-icon-s-home',
        url: '/index',
    },
    {
        name: '订单管理',
        icon: 'el-icon-s-order',
        url: '/orders',
        children: [
            {
                name: '订单列表',
                icon: 'el-icon-user',
                url: '/orders/list',
            },
        ],
    },
    {
        name: '运单管理',
        icon: 'el-icon-menu',
        url: '/waybill',
        children: [
            {
                name: '运单列表',
                icon: 'el-icon-truck',
                url: '/waybill/list',
            },
        ],
    },
];
Mock.mock('http://localhost:8080/menu', 'get', () => {
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        data: menuList,
    };
});
/* 订单列表接口 */
Mock.mock('http://localhost:8080/orderList', 'post', req => {
    const { page, pageSize, keyword } = JSON.parse(req.body); // current page
    // current limit
    console.log('接口接收到参数', page, pageSize, keyword);
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        data: Mock.mock({
            [`list|${pageSize}`]: [
                {
                    'id|+1': 10000, //订单号
                    'status|1': [1, 4], //订单状态 1待审核 2已审核 3审核通过 4审核拒绝
                    date: Mock.Random.date(), //下单时间
                    'name': [
                        '某公司',
                    ], //客户名称
                    'cargo': ['产品'], //货物名称
                    count: Mock.Random.integer(1, 200), //件数
                    price: Mock.Random.float(1000, 10000, 2, 2), //运费
                    'from|1': ['移动端', 'PC端'], //来源
                    'pay|1': [1, 2], //支付状态 1已支付 2未支付
                },
            ],
            total: 500,
        }),
    };
});
Mock.mock('http://localhost:8080/orderDelete', 'post', req => {
    const { page, pageSize, keyword } = JSON.parse(req.body); // current page
    // current limit
    console.log('接口接收到参数', page, pageSize, keyword);
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        data: Mock.mock({
            [`list${pageSize}`]: [
                {
                    'id': 10000, //订单号
                    date: Mock.Random.date(), //下单时间
                    'name': [
                        '公司'
                    ], //客户名称
                    'cargo': ['产品1'], //货物名称
                    count: Mock.Random.integer(1, 200), //件数
                    price: Mock.Random.float(1000, 10000, 2, 2), //运费
                    'from': ['移动端', 'PC端'], //来源
                    'pay': [1, 2], //支付状态 1已支付 2未支付
                },
            ],
            total: 500,
        }),
    };
});
// 订单管理-新建订单
Mock.mock('http://localhost:8080/addOrder', 'post', req => {
    const { name, cargo, count, price, from, pay } = JSON.parse(req.body);
    console.log('接口接收到参数', name, cargo, count, price, from, pay);
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        data: {
            id: Mock.Random.integer(10000, 99999), //订单号
        },
    };
});
//运单管理接口-运单列表
Mock.mock('http://localhost:8080/waybillList', 'post', req => {
    const { page, pageSize, waybillNo, name, startDate, endDate, status } = JSON.parse(req.body); // current page
    console.log('接口接收到参数', page, pageSize, waybillNo, name, startDate, endDate, status);
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        data: Mock.mock({
            [`list|${pageSize}`]: [
                {
                    'no|+1': 10000, //运单号
                    date: Mock.Random.date(), //下单时间
                    'name|1': [
                        '某公司',
                    ], //客户名称
                    'cargo|1': ['货物'], //货物名称
                    count: Mock.Random.integer(1, 200), //件数
                    start: Mock.Random.city(true), //起始城市
                    end: Mock.Random.city(true), //目的城市
                    price: Mock.Random.float(1000, 10000, 2, 2), //运费
                    'needRecive|1': [1, 2], //是否需要接货 1是 2否
                    'plateNumber|1': ['浙XXXXXXXX'], //车牌号
                    driver: Mock.Random.cname(), //司机姓名
                    'tel|1': ['1323333333'], //司机电话
                    'percent|1': [37, 22, 89, 65, 80, 74, 56],
                },
            ],
            total: 500,
        }),
    };
});
//根据token获取权限名字
Mock.mock('http://localhost:8080/getRole', 'get', () => {
    return {
        code: 200,
        success: true,
        msg: '请求成功',
        role: 'administration',
    };
});
